package com.pengcheng.taskapplication.mvp.view.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import com.pengcheng.taskapplication.R;
import com.pengcheng.taskapplication.contants.ConstantValue;
import com.pengcheng.taskapplication.helper.ImageLoader;
import com.pengcheng.taskapplication.model.BannerModel;
import com.pengcheng.taskapplication.model.CarModel;
import com.pengcheng.taskapplication.model.CheckModel;
import com.pengcheng.taskapplication.model.DeviceStatusModel;
import com.pengcheng.taskapplication.model.ParkOrderModel;
import com.pengcheng.taskapplication.model.SubscribeOrderListModel;
import com.pengcheng.taskapplication.model.UserDetailVo;
import com.pengcheng.taskapplication.mvp.presenter.UserPresenter;
import com.pengcheng.taskapplication.mvp.presenter.UserPresenterV2;
import com.pengcheng.taskapplication.net.ConvertUtil;
import com.pengcheng.taskapplication.net.IView;
import com.pengcheng.taskapplication.util.DisplayHelper;
import com.pengcheng.taskapplication.util.SPUtils;
import com.pengcheng.taskapplication.util.ToastUtils;
import com.pgyersdk.update.DownloadFileListener;
import com.pgyersdk.update.PgyUpdateManager;
import com.pgyersdk.update.UpdateManagerListener;
import com.pgyersdk.update.javabean.AppBean;
import com.squareup.picasso.Picasso;
import com.uuzuche.lib_zxing.activity.CodeUtils;
import com.yanzhenjie.permission.Action;
import com.yanzhenjie.permission.AndPermission;
import com.yanzhenjie.permission.Permission;
import com.youth.banner.Banner;
import com.zhouwei.indicatorview.CircleIndicatorView;
import com.zhouwei.mzbanner.MZBannerView;
import com.zhouwei.mzbanner.holder.MZHolderCreator;
import com.zhouwei.mzbanner.holder.MZViewHolder;

import java.io.File;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by ZFT on 2020/10/25.
 */

public class IndexTestActivity extends BaseActivity implements IView {
    private static final int REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSIONS = 1;
    private static final int REQUEST_CODE_WRITE_EXTERNAL_STORAGE = 2;
    private int page = 1;
    private int size = 10;
    private long certid;


//    @BindView(R.id.rl_top)
//    RelativeLayout rl_top;

    @BindView(R.id.top_banner)
    MZBannerView topZannerView;

    @BindView(R.id.radiogroup)
    RadioGroup radioGroup;

    @BindView(R.id.ll_top)
    LinearLayout ll_top;
    @BindView(R.id.img_bg)
    ImageView img_bg;


    public String token;


    private UserDetailVo userDetailVo;
    private UserPresenter userPresenter;
    private UserPresenterV2 userPresenterV2;
    private long from;
    private static final int REQUEST_CODE = 121;


    private String uid;
    private String newtoken;
    private String washid = "";
    private String deviceid = "";

    @Override
    protected int layoutResID() {
        return R.layout.activity_index_test_layout;
    }

    @Override
    protected void initData() {
        userPresenter = new UserPresenter(this);
        userPresenterV2 = new UserPresenterV2(this);
        token = SPUtils.getString(context, ConstantValue.SpType.token);
        uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        newtoken = SPUtils.getString(context, ConstantValue.SpType.newtoken);
        initSize();
        requestGranted();
        checkUpate();
        getBanner();
    }

    public void initSize() {
        double height = (DisplayHelper.getDisplayMetrics(context).widthPixels-DisplayHelper.dp2px(context,25)) / (690 / 402.0);
        ViewGroup.LayoutParams params = topZannerView.getLayoutParams();
        params.height = (int) (height);
        topZannerView.setLayoutParams(params);


        double height2 = (DisplayHelper.getDisplayMetrics(context).widthPixels) / (375 / 366.0);
        FrameLayout.LayoutParams params2 = (FrameLayout.LayoutParams) img_bg.getLayoutParams();
        params2.height = (int) (height2);
        img_bg.setLayoutParams(params2);
    }


    public void requestGranted() {
        //动态请求权限
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(
                        new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                        REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSIONS);
                requestPermissions(
                        new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
                        REQUEST_CODE_WRITE_EXTERNAL_STORAGE);
            }
        }
    }

    @Override
    public void onSuccess(String code, String msg, Object data, String actionType) {
        if (actionType.equals(ConstantValue.RequestKey.getSubscribes)) {
            ArrayList<SubscribeOrderListModel> list = (ArrayList<SubscribeOrderListModel>) data;
            if (list.size() == 0) {
                Intent intent = new Intent(context, Html5AgressActivity.class);
                intent.putExtra("url", "file:///android_asset/instructions.html");
                intent.putExtra("title", "办理须知");
                startActivity(intent);
            } else {
                Intent intent = new Intent(context, MyApplyAndCarsList.class);
                intent.putExtra("from", 0l);
                startActivity(intent);
            }
        }
        if (actionType.equals(ConstantValue.RequestKey.checkCert)) {
            CheckModel model = (CheckModel) data;
            if (model != null) {
                certid = model.getCertId();
            }
//            if(model.getCertId()==-1){
//                Intent intent =new Intent(context,UploadIdCard.class);
//                intent.putExtra("from",from);
//                intent.putExtra("flag",0l);
//                intent.putExtra("certId",model.getCertId());
//                startActivity(intent);
//            }else if(model.getCertId()>0&!model.isFrontOcrFlag()&!model.isBackOcrFlag()){
//                Intent intent =new Intent(context,UploadIdCard.class);
//                intent.putExtra("certId",model.getCertId());
//                //flag为1的时候，需要回显，重新认证
//                intent.putExtra("flag",1l);
//                intent.putExtra("from",from);
//                startActivity(intent);
//            }else {
//                //用户是否开卡
//                if(userDetailVo!=null) {
//                    //未开卡
//                    if (!userDetailVo.isHasIcbcAuth()) {
//                            //
//                        //到绑卡页面
//                        Intent intent = new Intent(context, BindCardActivity.class);
//                        intent.putExtra("from",from);
//                        intent.putExtra("certId",model.getCertId());
//                        startActivity(intent);
//                    } else {
//                        //已经开卡
//
//                        if(from==0) {
//                            getSubscribes(page,size);
//
//                        }else {
//                            Intent intent = new Intent(context, MyBankList.class);
//                            startActivity(intent);
//                        }
//                    }
//                }
//
//            }
        }
        if (actionType.equals(ConstantValue.RequestKey.getBanner)) {
            ArrayList<BannerModel> bannerModels = (ArrayList<BannerModel>) data;
            setTopBanner(bannerModels);
        }

        if (actionType.equals(ConstantValue.RequestKey.commitOrder)) {

            Gson gson = new Gson();
            Type type = new TypeToken<ParkOrderModel>() {
            }.getType();
            ParkOrderModel parkOrderModel = gson.fromJson(gson.toJson(data), type);

            Intent intent = new Intent(context, ConfrimOrderActivity.class);
            intent.putExtra("tradno", parkOrderModel.getTradno());
            startActivity(intent);

        }

        if (actionType.equals(ConstantValue.RequestKey.getCars)) {
            ArrayList<CarModel> carModels= (ArrayList<CarModel>)data;
            if (carModels==null||carModels.size()==0){
                ToastUtils.showShortToast("您尚未安装电子车牌");
            }else{
                Intent  intent = new Intent(context, MyApplyAndCarsList.class);
                intent.putExtra(ConstantValue.IntentKey.KEY_FROM_TYPE, 1);
                startActivity(intent);
            }
        }
        if (actionType.equals(ConstantValue.RequestKey.getDeviceStatus)) {
            DeviceStatusModel deviceStatusModel = (DeviceStatusModel) data;

            String carready=deviceStatusModel.getCarready();
            String washing=deviceStatusModel.getWashing();
            String washdong=deviceStatusModel.getWashdone();
            if(carready.equals("0")&&washing.equals("0")&&washdong.equals("0")){
                //当前设备空载
                ToastUtils.showShortToast("车辆没有停到位，请按照指示灯要求停车入位");
                return;
            }
            if(carready.equals("1")&&washing.equals("0")&&washdong.equals("0")){
                //停好车了
                Intent intent =new Intent(context,WashCommitActivity.class);
                intent.putExtra("washid", washid);
                intent.putExtra("deviceid", deviceid);
                startActivity(intent);
            }
            if(carready.equals("0")&&washing.equals("1")&&washdong.equals("0")){
                //洗车中
                ToastUtils.showShortToast("车辆正在清洁中，请等待");
                return;
            }
            if(carready.equals("0")&&washing.equals("0")&&washdong.equals("1")){
                //洗车完成
            }

            //正在洗车中
            //当前设备没有订单
//            if (deviceStatusModel.getCurrenttradno().length() == 0) {
//                if (deviceStatusModel.carready.equals("0")) {
//                    ToastUtils.showShortToast("车辆没有停到位，请按照指示灯要求停车入位");
//                } else if (deviceStatusModel.carready.equals("1")) {
//                    //停车到位
//                    if (deviceStatusModel.washing.equals("1")) {
//                        ToastUtils.showShortToast("已有车辆在洗车，请等待");
//                    } else if (deviceStatusModel.washing.equals("0")) {
//                        Intent intent = new Intent(context, WashCommitActivity.class);
//                        intent.putExtra("washid", washid);
//                        intent.putExtra("deviceid", deviceid);
//                        startActivity(intent);
//                    }
//                }
//            } else {
//                ToastUtils.showShortToast("当前设备有未完成的订单，不可驶入");
//            }

        }
        if (actionType.equals(ConstantValue.RequestKey.userinfo)) {
            userDetailVo = (UserDetailVo) data;
            if (userDetailVo != null) {
                SPUtils.putString(context, ConstantValue.SpType.phone, userDetailVo.getCellphone());
                //未实名
                if (!userDetailVo.isHasRealNameAuth()) {
                    Intent intent = new Intent(context, UploadIdCard.class);
                    intent.putExtra("from", from);
                    intent.putExtra("flag", 0l);
                    //intent.putExtra("certId",certid);
                    startActivity(intent);
                } else {
//                    //未开卡
//                    if (!userDetailVo.isHasIcbcAuth()) {
//                        //
//                        //到绑卡页面
//                        Intent intent = new Intent(context, BindCardActivity.class);
//                        intent.putExtra("from",from);
//                       // intent.putExtra("certId",certid);
//                        startActivity(intent);
//                    } else {
                    //已经开卡
                    //跳转到绑卡列表
                    if (from == 0) {
                        getSubscribes(page, size);
                    } else {
                        //银行列表
                        Intent intent = new Intent(context, MyBankList.class);
                        startActivity(intent);
                    }
//                    }

                }

            }
        }
    }

    @Override
    public void onFailed(String code, String msg) {
        ToastUtils.showShortToast(msg);
    }


    @OnClick({R.id.rl_dzcp, R.id.rl_tc, R.id.rl_xc, R.id.ll_my_info, R.id.ll_wash, R.id.img_scan, R.id.clgj})
    public void onViewClicked(View view) {
        Intent intent;
        switch (view.getId()) {
            case R.id.rl_dzcp:
                from = 0l;
                if (check(token)) {
                    getUserDetail();
                }
                break;
            case R.id.clgj:
                if (check(token)) {
                    getCars(1, 100, false);
                }
                break;
            case R.id.ll_my_info:
                from = 4l;
                if (check(token)) {
                    intent = new Intent(context, MyInfo.class);
                    startActivity(intent);
                }
                break;
            case R.id.ll_wash:
                intent = new Intent(context, ParkWashActivity.class);
                startActivity(intent);
                break;

            case R.id.rl_tc:
                from = 2l;
                if (check(token)) {
                    intent = new Intent(context, ParkScanActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.rl_xc:
                from = 3l;
                if (check(token)) {
                    intent = new Intent(context, ParkWashActivity.class);
                    startActivity(intent);
                }
                break;
            case R.id.img_scan:
                AndPermission.with(this)
                        .permission(Permission.CAMERA, Permission.READ_EXTERNAL_STORAGE, Permission.WRITE_EXTERNAL_STORAGE)
                        .onGranted(new Action() {
                            @Override
                            public void onAction(List<String> permissions) {
                                Intent intent = new Intent(context, QrScanActivity.class);
                                startActivityForResult(intent, REQUEST_CODE);
                            }
                        })
                        .onDenied(new Action() {
                            @Override
                            public void onAction(List<String> permissions) {
                                Uri packageURI = Uri.parse("package:" + getPackageName());
                                Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
                                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                startActivity(intent);
                                Toast.makeText(context, "没有权限", Toast.LENGTH_LONG).show();
                            }
                        }).start();
                break;
        }
    }


    public boolean check(String token) {
        token = SPUtils.getString(context, ConstantValue.SpType.token);
        if (token == null || token.length() == 0) {
            Intent intent = new Intent(context, LoginActivity.class);
            intent.putExtra("from", from);
            startActivity(intent);
            return false;
        } else {
            return true;
        }
    }

    ;

    @Override
    protected void onResume() {
        super.onResume();
        token = SPUtils.getString(context, ConstantValue.SpType.token);
        uid = SPUtils.getString(context, ConstantValue.SpType.userid);
        newtoken = SPUtils.getString(context, ConstantValue.SpType.newtoken);
    }

    public void checkOcr() {
        userPresenter.checkCert(ConstantValue.RequestKey.checkCert);
    }

    public void checkList() {
        userPresenter.checkCert(ConstantValue.RequestKey.checkList);
    }



    public void getCars(int page,int pageSize,boolean showAll){
        userPresenter.getCars(page,pageSize, showAll,ConstantValue.RequestKey.getCars);
    }

    public void getBanner() {
        userPresenterV2.getBanner(ConstantValue.RequestKey.getBanner);
    }

    public void getSubscribes(int page, int pageSize) {
        userPresenter.getSubscribes(page, pageSize, ConstantValue.RequestKey.getSubscribes);
    }

    public void getUserDetail() {
        userPresenter.getUserDetail(ConstantValue.RequestKey.userinfo);
    }

    public void checkUpate() {
        /** 新版本 **/

        new PgyUpdateManager.Builder()
                .setForced(true)                //设置是否强制更新,非自定义回调更新接口此方法有用
                .setUserCanRetry(false)         //失败后是否提示重新下载，非自定义下载 apk 回调此方法有用
                .setDeleteHistroyApk(false)     // 检查更新前是否删除本地历史 Apk
                .setUpdateManagerListener(new UpdateManagerListener() {
                    @Override
                    public void onNoUpdateAvailable() {
                        //没有更新是回调此方法
                        Log.d("pgyer", "there is no new version");
                    }

                    @Override
                    public void onUpdateAvailable(AppBean appBean) {
                        //没有更新是回调此方法
                        Log.d("pgyer", "there is new version can update"
                                + "new versionCode is " + appBean.getVersionCode());


                        //调用以下方法，DownloadFileListener 才有效；如果完全使用自己的下载方法，不需要设置DownloadFileListener
                        PgyUpdateManager.downLoadApk(appBean.getDownloadURL());
                    }

                    @Override
                    public void checkUpdateFailed(Exception e) {
                        //更新检测失败回调
                        Log.e("pgyer", "check update failed ", e);

                    }
                })
                //注意 ：下载方法调用 PgyUpdateManager.downLoadApk(appBean.getDownloadURL()); 此回调才有效
                .setDownloadFileListener(new DownloadFileListener() {   // 使用蒲公英提供的下载方法，这个接口才有效。
                    @Override
                    public void downloadFailed() {
                        //下载失败
                        Log.e("pgyer", "download apk failed");
                    }

                    @Override
                    public void downloadSuccessful(File file) {
                        Log.e("pgyer", "download apk failed");
                        PgyUpdateManager.installApk(file);  // 使用蒲公英提供的安装方法提示用户 安装apk

                    }

                    @Override
                    public void onProgressUpdate(Integer... integers) {
                        Log.e("pgyer", "update download apk progress : " + integers[0]);
                    }
                })
                .register();
    }


    @SuppressLint("NewApi")
    @Override
    public void onRequestPermissionsResult(int requestCode,
                                           String[] permissions, int[] grantResults) {
        switch (requestCode) {
            case REQUEST_CODE_WRITE_EXTERNAL_STORAGE: {
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                        //Toast.makeText(this, "允许写存储！", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "未允许写存储！", Toast.LENGTH_SHORT).show();
                    }

                }
            }
            case REQUEST_CODE_READ_EXTERNAL_STORAGE_PERMISSIONS: {
                for (int i = 0; i < permissions.length; i++) {
                    if (grantResults[i] == PackageManager.PERMISSION_GRANTED) {
                        //Toast.makeText(this, "允许读存储！", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(this, "未允许读存储！", Toast.LENGTH_SHORT).show();
                    }

                }
            }
            break;
            default: {
                super.onRequestPermissionsResult(requestCode, permissions,
                        grantResults);
            }
        }
    }

    private void setTopBanner(List<BannerModel> banners) {

        for (int i = 0; i < banners.size(); i++) {
            RadioButton button = new RadioButton(context);
            button.setButtonDrawable(R.drawable.radio_button_style);
            button.setPadding(10, 0, 10, 0);
            radioGroup.addView(button);
        }
        radioGroup.check(radioGroup.getChildAt(0).getId());
        topZannerView.addPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                //Log.e("zw","onPageScrolled---->"+position);
                radioGroup.check(radioGroup.getChildAt(position).getId());
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        topZannerView.setPages(banners, new MZHolderCreator<TopBannerViewHolder>() {
            @Override
            public TopBannerViewHolder createViewHolder() {
                return new TopBannerViewHolder();
            }
        });
        topZannerView.start();
        topZannerView.setIndicatorVisible(false);

    }

    /**
     * status (integer, optional): 状态 1发布 2未发布 ,
     * type (integer, optional): 类型 1：内链 2：外链 ,
     * url (string, optional): 跳转链接(http或内部标识) ,
     *
     * carNum                智慧车牌
     * carHousekeeper   车辆管家
     * personalCenter   个人中心
     * parking     停车场
     * washing             洗车房
     */

    public class TopBannerViewHolder implements MZViewHolder<BannerModel> {
        private ImageView mImageView;

        @Override
        public View createView(Context context) {
            View view = LayoutInflater.from(context).inflate(R.layout.banner_item_layout, null);
            mImageView = (ImageView) view.findViewById(R.id.banner_img);
            mImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                   BannerModel bannerModel =(BannerModel) v.getTag();
                   if(bannerModel!=null){
                       if(bannerModel.type.equals("1")){
                            switch (bannerModel.url){
                                case "carNum":
                                    from = 0l;
                                    if (check(token)) {
                                        getUserDetail();
                                    }
                                    break;
                                case "carHousekeeper":
                                    from = 5l;
                                    if (check(token)) {
                                        Intent  intent = new Intent(context, MyApplyAndCarsList.class);
                                        intent.putExtra(ConstantValue.IntentKey.KEY_FROM_TYPE, 1);
                                        startActivity(intent);
                                    }
                                    break;
                                case "personalCenter":
                                    if (check(token)) {
                                        Intent intent = new Intent(context, MyInfo.class);
                                        startActivity(intent);
                                    }
                                    break;
                                case "parking":
                                    from = 2l;
                                    if (check(token)) {
                                        Intent  intent = new Intent(context, ParkScanActivity.class);
                                        startActivity(intent);
                                    }
                                    break;

                                case  "washing":
                                    from = 3l;
                                    if (check(token)) {
                                        Intent intent = new Intent(context, ParkWashActivity.class);
                                        startActivity(intent);
                                    }
                                    break;
                            }
                       }else{
                           Intent intent =new Intent(context,Html5Activity.class);
                           intent.putExtra("url",bannerModel.getUrl());
                           startActivity(intent);
                       }
                   }
                }
            });
            return view;
        }

        @Override
        public void onBind(Context context, int i, BannerModel bannerModel) {
            Log.e("zhouwei", "current position:" + i);
            ImageLoader.displayImage(context, bannerModel.getIcon(), mImageView);
            mImageView.setTag(bannerModel);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        topZannerView.pause();
    }

    @SuppressWarnings("unchecked")
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        /**
         * 处理二维码扫描结果
         */
        if (requestCode == REQUEST_CODE) {
            //处理扫描结果（在界面上显示）
            if (null != data) {
                Bundle bundle = data.getExtras();
                if (bundle == null) {
                    return;
                }
                if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_SUCCESS) {
                    String result = bundle.getString(CodeUtils.RESULT_STRING);
                    //如果是url 跳转到http 页面
                    if (ConvertUtil.isHttpUrl(result)) {
                        Intent intent = new Intent(context, Html5Activity.class);
                        intent.putExtra("url", result);
                        startActivity(intent);
                    } else {
                        //如果是扫码的洗车或者停车二维码
                        if (ConvertUtil.validate(result)) {
                            try {
                                JsonObject jsonObject = (JsonObject) new JsonParser().parse(result).getAsJsonObject();
                                String type = jsonObject.get("type").getAsString();
                                if (type.equals("parkIn")) {
                                    //获取停车场的id 和通道
                                    String parkid = jsonObject.get("parkid").getAsString();
                                    String laneno = jsonObject.get("laneno").getAsString();
                                    //进入通道
                                    inPark(newtoken, uid, parkid, laneno);
                                } else if (type.equals("parkExit")) {
                                    //获取停车场的id 和通道
                                    String parkid = jsonObject.get("parkid").getAsString();
                                    String laneno = jsonObject.get("laneno").getAsString();
                                    //进入通道
                                    outPark(newtoken, uid, parkid, laneno);
                                } else if (type.equals("wash")) {
                                    //获取停车场的id
                                    washid = jsonObject.get("washid").getAsString();
                                    deviceid = jsonObject.get("deviceid").getAsString();
                                    //解析成功后，扫出码中信息，然后弹窗,缓存下
                                    //扫码出设备id需要判断设备准备好
                                    geDeviceStatus(newtoken, uid, deviceid);
                                    //showDialog(washTypeModelArrayList);
                                }
                            } catch (Exception e) {
                                ToastUtils.showShortToast("请扫码正确的二维码");
                            }
                        }
                    }
                } else if (bundle.getInt(CodeUtils.RESULT_TYPE) == CodeUtils.RESULT_FAILED) {
                    Toast.makeText(context, "解析二维码失败,请重新扫码", Toast.LENGTH_LONG).show();
                }
            }
        }
    }

    public void inPark(String token, String uid, String parkid, String laneno) {
        userPresenterV2.commitOrder(token, uid, parkid, laneno, ConstantValue.RequestKey.inPark);
    }

    public void outPark(String token, String uid, String parkid, String laneno) {
        userPresenterV2.commitOrder(token, uid, parkid, laneno, ConstantValue.RequestKey.commitOrder);
    }

    public void geDeviceStatus(String token, String uid, String deviceid) {
        userPresenterV2.getStatus(token, uid, deviceid, ConstantValue.RequestKey.getDeviceStatus);
    }
}
